import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);
const types = {
  SET_Auth: 'SET_LOCATION',
  SET_UID:'SET_UID',
  SET_TIME:'SET_TIME'
};

export default new Vuex.Store({
  getters:{
    token: state => state.token,
  },
  state: {
    token:""
  },
  mutations: {
    [types.SET_Auth](state,token) {
      if (token) {
        state.token = token;
        uni.setStorage({
          key:'token',
          data:token
        })
      } else {
        state.token = '';
      }
    },
  },
  actions: {
    setAuth: ({ commit }, token) => {
      commit(types.SET_Auth, token);
    },
  },
  modules: {},
});
